import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘国水
 * Date: 2025-04-24
 * Time: 21:06
 */
public class Main {
    public int[] elem;
    public int usedSize;


    public MyStack() {
        elem = new int[Constant.DEFAULT_CAPACITY];
    }

    //进栈
    public void push(int val) {
        if(isFull()) {
            elem = Arrays.copyOf(elem,2*elem.length);
        }

        elem[usedSize] = val;
        usedSize++;
    }

    public boolean isFull() {
        return usedSize == elem.length;
    }

    //出栈，并删除栈顶元素
    public int pop(){
        if(isEmpty()) {
            throw new EmptyFull(Constant.EMPTY_FULL);
        }

        int ret = elem[usedSize-1];
        usedSize--;
        return ret;
    }

    private boolean isEmpty() {
        return usedSize ==0;
    }

    //获取栈顶元素，但不删除
    public int peek() {
        if(isEmpty()) {
            throw new EmptyFull(Constant.EMPTY_FULL);
        }

        int ret = elem[usedSize-1];
        return ret;
    }

}
